package cn.me.alphamq.common.lock;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 自旋的间隙锁
 *
 * @author f
 */
public class SpinLock implements WriteDataLock {

    private final AtomicInteger lock = new AtomicInteger(0);

    @Override
    public void lock() {
        do {
            if (lock.incrementAndGet() == 1) {
                return;
            }
        } while (true);
    }

    @Override
    public void unlock() {
        lock.decrementAndGet();
    }
}
